<template>
  <div>
    <div>
      <el-card shadow="never">
        <div class="search-box">
          <el-form ref="form" label-width="5rem">
            <el-form-item label="关键字:">
              <el-input
                placeholder="根据编号搜索"
                style="width: 18.75rem"
                v-model="params.keyword"
              ></el-input>
            </el-form-item>
          </el-form>
          <div class="appade">
            <el-button @click="eliMinate">清除</el-button>
            <el-button type="primary" @click="searchList">搜索</el-button>
          </div>
        </div>
        <el-alert :title="alertText" type="info" :closable="false" show-icon>
        </el-alert>
        <template>
          <el-table style="width: 100%" :data="addList" row-key="id">
            <el-table-column label="编号" width="230px" prop="id">
            </el-table-column>
            <el-table-column label="题型" width="100px" prop="questionType">
              <template v-slot="scoped">
                <p v-if="scoped.row.questionType == '1'">单选</p>
                <p v-else-if="scoped.row.questionType == '2'">多选</p>
                <p v-else-if="scoped.row.questionType == '3'">简答题</p>
              </template>
            </el-table-column>
            <el-table-column label="题目编号" prop="" width="200px">
              <template v-slot="scope">
                <div
                  v-for="(item, index) in scope.row.questionIDs"
                  :key="index"
                >
                  <p class="number" @click="previewList(item)">{{ item.number }}</p>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="录入时间" prop="addTime" width="200px">
            </el-table-column>
            <el-table-column
              label="答题时间(s)"
              prop="totalSeconds"
              width="150px"
            >
            </el-table-column>
            <el-table-column
              label="正确率(%)"
              prop="accuracyRate"
              width="150px"
            >
            </el-table-column>
            <el-table-column label="录入人" prop="userName"> </el-table-column>
            <el-table-column label="操作">
              <template v-slot="scoped">
                <el-button
                  type="danger"
                  icon="el-icon-delete"
                  circle
                  @click="delList(scoped.row)"
                ></el-button>
              </template>
            </el-table-column>
          </el-table>
        </template>
        <!-- 分页 -->
          <el-row>
              <el-col :span="12"><div class="grid-content bg-purple li-ste  "></div></el-col>
              <el-col :span="12"><div class="grid-content li-ste bg-purple-light">
                <el-pagination
                  @size-change="handleSizeChange"
                  :current-page="params.page"
                  :page-sizes="[20, 30, 40, 50]"
                  :page-size="params.pagesize"
                  @current-change="handleCurrentChange"
                  layout="  prev, pager, next, sizes,jumper"
                  :total="counts"
                   >
        </el-pagination></div></el-col>
          </el-row>

      </el-card>
    </div>
    <el-dialog
      title="题目预览"
      :visible="dialogVisible"
      width="900px"
      @close="closeDialog"
    >
      <el-row :gutter="20" class="preview">
        <el-col :span="6"
          >【题型】：{{
            preview.questionType == 1
              ? "单选题"
              : preview.questionType == 2
              ? "多选题"
              : "简答题"
          }}</el-col
        >
        <el-col :span="6">【编号】：{{ preview.id }}</el-col>
        <el-col :span="6"
          >【难度】：{{
            preview.difficulty == 1
              ? "简单"
              : preview.questionType == 2
              ? "一般"
              : "困难"
          }}</el-col
        >
        <el-col :span="6">【标签】：{{ preview.tags }}</el-col>
      </el-row>
      <el-row :gutter="20" class="preview">
        <el-col :span="6">【学科】：{{ preview.subjectName }}</el-col>
        <el-col :span="6">【目录】：{{ preview.directoryName }}</el-col>
        <el-col :span="6">【方向】：{{ preview.direction }}</el-col>
      </el-row>
      <hr />
      <div>【题干】:</div>
      <div style="color: blue" class="general" v-html="preview.question"></div>
      <div class="general check">
        <!-- 单选  -->
        <div v-if="preview.questionType == 1">
          <p>
            {{
              preview.questionType == 1
                ? "单选题"
                : preview.questionType == 2
                ? "多选题"
                : "简答题"
            }}
            选项:（以下选中的选项为正确答案）
          </p>
          <div
            v-for="item in preview.options"
            :key="item.id"
            style="padding: 8px 0px"
          >
             <el-checkbox
              :checked="item.isRight === 1 ? true : false"
              onclick="return false"
              >{{ item.title }}</el-checkbox
            >
          </div>
        </div>
        <!-- 多选  -->
        <div v-else-if="preview.questionType == 2">
          <p>
            {{
              preview.questionType == 1
                ? "单选题"
                : preview.questionType == 2
                ? "多选题"
                : "简答题"
            }}
            选项:（以下选中的选项为正确答案）
          </p>
          <div
            v-for="item in preview.options"
            :key="item.id"
            style="padding: 8px 0px"
          >
            <el-checkbox
              :checked="item.isRight === 1 ? true : false"
              onclick="return false"
              >{{ item.title }}</el-checkbox
            >
          </div>
        </div>
        <!-- 简答  -->
        <div v-else></div>
      </div>
      <hr />
      <div class="general">
        【参考答案】：
        <el-button type="danger" @click="okqie"
          >视频答案预览</el-button
        >
        <div v-show="isShow">
          <video
          ref="vueRef"
           src= https://vkceyugu.cdn.bspapp.com/VKCEYUGU-learning-vue/52e63a10-aecd-11ea-b43d-2358b31b6ce6.mp4
           controls="controls"
            height="200px"
            width="300px"
            autoplay
          ></video>
        </div>
      </div>
      <hr />
      <div class="general">
        【答案解析】：
        <div style="display: inline-block" v-html="preview.answer"></div>
      </div>
      <hr />
      <div class="general">【题目备注】：{{ preview.remarks }}</div>
      <span slot="footer" class="dialog-footer">
        <div style="text-align: right">
          <el-button type="primary" @click="closeDialog">关 闭</el-button>
        </div>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { randoms, removeRandoms, detail } from '@/api/hmmm/questions.js'
export default {
  data () {
    return {
      dialogVisible: false, // 预览弹窗
      alertText: '',
      preview: {},
      addList: [],
      params: {
        page: 1,
        pagesize: 20,
        keyword: ''
      },
      counts: 0,
      isShow: false // 视频答案预览显示
    }
  },
  mounted () {
    this.getList()
  },
  methods: {
    // // 难度转换
    // difficulty (num) {
    //   if (num === '1') return '简单'
    //   if (num === '2') return '一般'
    //   if (num === '3') return '困难'
    // },
    // // 题型转换
    // jquestionType (type) {
    //   if (type === '1') return '单选'
    //   if (type === '2') return '多选'
    //   if (type === '3') return '简答'
    // },
    // 改变了每页数据条数的时候，触发这个事件
    handleSizeChange (newSize) {
      this.params.pagesize = newSize
      this.params.page = 1
      this.getList()
    },
    // 页码改变的时候，触发的事件
    handleCurrentChange (newPage) {
      // console.log(newPage) // 表示点击的，或者跳转的最新的页码值
      this.params.page = newPage
      this.getList()
    },
    // 获取数据渲染页面
    async getList () {
      const res = await randoms(this.params)
      console.log(res)
      this.addList = res.data.items
      this.counts = res.data.counts
      this.alertText = `共 ${this.counts} 条记录`
    },
    // 删除
    delList (id) {
      this.$confirm('此操作将永久删除该题目, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          console.log(id)
          await removeRandoms(id)
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
          // 更新列表
          this.getList()
        })
        .catch(() => {})
    },
    // 搜索
    async searchList () {
      // console.log(this.params.keyword)
      const res = await randoms(this.params)
      // console.log(res)
      this.addList = res.data.items
      this.counts = res.data.counts
      this.params.page = 1
      this.getList()
      this.alertText = `共 ${this.counts} 条记录`
    },
    // 清除
    eliMinate () {
      this.params.keyword = ''
      this.getList()
    },
    // 题目编号按钮
    async previewList (item) {
      // console.log(item)
      this.isNext = true
      this.dialogVisible = true
      const { data: res } = await detail(item)
      this.preview = res
      console.log(this.preview)
      this.$refs.vueRef.pause()// 暂停
    },
    closeDialog () {
      this.isShow = false
      this.dialogVisible = false
      this.$refs.vueRef.load()// 初始化
      this.$refs.vueRef.pause()// 暂停
    },
    okqie () {
      this.isShow = !this.isShow
      if (this.isShow === false) {
        this.$refs.vueRef.pause()// 暂停
      } else {
        this.$refs.vueRef.play()// 播放
      }
    }
    // appqadDaw () {
    //   this.false = true
    // }
  }
}
</script>
<style rel="stylesheet/less" lang="scss" scoped>
.search-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}
.appade {
  margin-right: 50px;
}
.number {
  color: #09f;
  cursor: pointer;
  line-height: 10px;
}
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}

.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.add-pink {
  height: 70px;
}
.app-ss {
  padding-top: 10px;
}
.li-ste{
  margin-top: 15px;
}
</style>
